package com.combetter.changxing.net;

import android.support.annotation.IntDef;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Created by Mark.fan on 2018/5/4.
 */

public class Resource<T> {
    //使用注解代替枚举
    public static final int LOADING = 0;
    public static final int MORE_ADD = 1;
    public static final int SUCCESS = 2 ;
    public static final int ERROR = 3;

    @IntDef({LOADING, MORE_ADD, SUCCESS, ERROR})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Status {}

   @Status
    public int status;

    @Nullable
    public String message;

    @NotNull
    public T data;

    public Resource(@Status int status, T data, String message) {
        this.status = status;
        this.data = data;
        this.message = message;
    }
    public static <T>Resource<T> success(@NotNull T data) {
        return new Resource<>(SUCCESS, data, null );
    }

    public static <T> Resource<T> loading(@android.support.annotation.Nullable T data, String msg) {
        return new Resource<>(LOADING, data, msg);
    }
}
